import http from '@ohos.net.http';
import PreferencesUtil from '../untils/PreferencesUtil';

export default class CommonConstants {
  static readonly FULL_WIDTH: string = '100%';
  static readonly FULL_HEIGHT: string = '100%';
  static readonly GENDERS: string[] = ['男', '女'];
  static readonly HEIGHT_RANGE: string[] = ["150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", "220"];
  static readonly WEIGHT_RANGE: string[] = ["30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120"];
  static readonly AGE_RANGE: string[] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"];
  static readonly FOOD_ICON_BASE_URL = 'https://healthyfood.xiake-half.com/foodIcon/'
  static readonly USER_AVATAR_BASE_URL = 'https://healthyfood.xiake-half.com/userAvatar/'
  static readonly PREF_NAME = 'healthyFood'
}

export const LOG_TAG = 'test Tag '

export const BASE_URL: string = 'https://healthyFood.xiake-half.com/api'

export const GET = http.RequestMethod.GET

export const POST = http.RequestMethod.POST

export const DELETE = http.RequestMethod.DELETE

export const PUT = http.RequestMethod.PUT

export class ResponseResult {
  private data: Object
  private status: number
  private msg: string

  constructor(response: http.HttpResponse) {
    let jsonValue = JSON.parse(response.result.toString())
    this.data = jsonValue.data
    this.msg = jsonValue.msg
    this.status = parseInt(jsonValue.status)
    console.info(LOG_TAG + JSON.stringify(this.data))
    console.info(LOG_TAG + this.status.toString())
    console.info(LOG_TAG + jsonValue.msg)
  }

  get Data() {
    return this.data
  }

  get Status() {
    return this.status
  }

  get Msg() {
    return this.msg
  }
}

export async function getToken() {
  // return 'eyJ0eXAiOiJqd3QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MDg1OTY3NTcsInVzZXJJZCI6MX0.jfkp6L0G71pv-vBZCMqSZKiQO_g_ZQX-WQCdmsnABjk'
  let token = await PreferencesUtil.getValue(CommonConstants.PREF_NAME, 'token', null)
  console.info(LOG_TAG + token.toString())
  return token
}